<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    session_start();
    $category = $_GET["category"];
    
    $con = mysql_connect("localhost", "zhouzhao", "19831022");
    if(!$con){
        die("could not connect to DB: ".mysql_error());
    }
    
    mysql_select_db("cloudcom", $con);
    
    if($category != 0){
        $result1 = mysql_query("select * from products where categoryID=".$category);
        $result2 = mysql_query("select * from products P, sales S where P.productID=S.productID and P.categoryID = ".$category);
    }else{
        $result1 = mysql_query("select * from products");
        $result2 = mysql_query("select * from products P, sales S where P.productID=S.productID");
    }
    
    echo "<table border='1' id='productTable'>";
    echo "<tr><th>Category ID</th><th>Product name</th><th>Product description</th><th>Product image</th><th>Product price</th><th>Select</th></tr>";
    
    while($row = mysql_fetch_assoc($result1)){
        echo "<tr>";
        echo "<td>".$row["categoryID"]."</td>";
        echo "<td>".$row["productName"]."</td>";
        echo "<td>".$row["productDescription"]."</td>";
        echo "<td><img src='images/products/".$row["productImage"]."' width='100' heigth='100' alt='image' /></td>";
        echo "<td>".$row["productPrice"]."</td>";
        echo "<td><input type='radio' name='productID' value='".$row["productID"]."'/></td>";
        echo "</tr>";        
    }
    
    mysql_close($con);
    
    echo "</table>";
echo "<table border='1' id='saleTable'>";
    echo "<tr><th>Category ID</th>
        <th>Product name</th>
        <th>Sale image</th>
        <th>Discount</th>
        <th>Start date</th>
        <th>End date</th></tr>";
    
    while($row = mysql_fetch_assoc($result2)){
        echo "<tr>";
        echo "<td>".$row["categoryID"]."</td>";
        echo "<td>".$row["productName"]."</td>";
        echo "<td><img src='images/products/sale.jpg' width='100' heigth='100' alt='image' /></td>";
        echo "<td>".$row["discount"]."</td>";
        echo "<td>".$row["startDate"]."</td>";
        echo "<td>".$row["endDate"]."</td>";
        echo "</tr>";        
    }
    
    echo "</table>";    
    
?>
